
/*http://zhengwu.beijing.gov.cn/zwzt/syss/default.htm*/

function channgeSubjectTopicBg(topic_bg_image)
{
	var src = topic_bg_image =='' ? "../pages/WebSubject/redzt/images/index2.jpg" : topic_bg_image;
	
	$("#bg_Image").attr("src",src);
}

/**
 * 图片新闻.
 */

function loadImageNew(topic_id,flag)
{
	//图片新闻
	$.ajax({  
		type: "POST",  
        url: '../WebSubject/queryArticleByTop.json', 
        cache:false,  
	    data:{		    	    	  
	    	topic_id:topic_id,
        	flag :flag,
	    },  		    	     
	    cache:false,  
	    dataType:'json',  
	    success:function(data) { 
	    	if(data!=null && data.length>0){		    	    		
	    		$.each(data,function(idx,obj){
	    			var maxwidth=25; 
	    			if(obj.title.length>maxwidth){
	    				obj.title=obj.title.substring(0,maxwidth);
	    				obj.title+=' ...';  
	    			}	    			
	    			var url='../WebSubject/detailMsgPage.htm?id='+obj.id +"&menu_id=" +obj.menu_id;	    			
	    			var addhtml = '<a href="'+url+'">' +
    						         '<img src="'+obj.img.split(',').shift()+'"  title="'+obj.title+'" />' +
    						      '</a>';
	                $("#focusImage").append(addhtml);	    	                
	    		});
	    		
	    		$('#focusImage').nivoSlider({
					 //effect: 'slideInRight',      
					 directionNav: false, //是否显示图片切换按钮(上/下页)
					 directionNavHide: true, //是否鼠标经过才显示
		        	 manualAdvance:true,	 
		             controlNav: true,               // 是否显示图片导航控制按钮（,2,3... ）  
		             controlNavThumbs: false,        // 是否使用图片的缩略图做为导航控制按钮
		             pauseOnHover: true            // 鼠标县浮时是否停止动画 
		        });			    	    		
	    	}	
	    },  
	     error : function(XMLHttpRequest, textStatus, errorThrown) {  
	          alert("异常！");  
	          alert(XMLHttpRequest.status);
	          alert(XMLHttpRequest.readyState);
	          alert(textStatus);
	     }  
	});
	
}




/**
 * 加载菜单.
 */
function loadMenu(topic_id){
	
	$.ajax({  
		type: "POST",  
        url: '../WebSubject/loadSubjectMenus.json',  
        data:{  
        	topic_id:topic_id,		    	    	  
	    },  
	    cache:false,  
	    dataType:'json',  
	    success:function(data) { 
	    	if(data!=null && data.length>0){
	    		initPage(data, topic_id);
	    		/*data.forEach(function(e){  
	    			switch (e.flag)
	    			{
		    			case "hddt": //活动动态.
		    				initHddt(topic_id, e.id);
		    				$("#zxxx_hddt_a").attr("href","../WebSubject/SubMenuPage.htm?id=" + e.id); 
		    				loadImageNew(topic_id, e.flag);
		    				break;
		    			case "gzdt":  //工作动态.
		    				$("#zyjs_gzdt").append(e.title);
		    				$("#zxxx_gzdt_a").attr("href","../WebSubject/SubMenuPage.htm?id=" + e.id); 
		    				initGzdt(topic_id,e.id);
		    				break;
		    			case "xgwj":   //相关文件
		    				$("#zyjs_xgwj").append(e.title);
		    				$("#zxxx_xgwj_a").attr("href","../WebSubject/SubMenuPage.htm?id=" + e.id); 
		    				initXgwj(topic_id,e.id );
		    			
		    				break;
		    			case "sjjs":   //上级精神
		    				$("#zypl").show();
		    				$("#zyjs_sjjs").append(e.title);
		    				$("#zxxx_sjjs_a").attr("href","../WebSubject/SubMenuPage.htm?id=" + e.id); 
		    				initSjjs(topic_id,e.id );
		    			
		    				break;
		    			case "bdth":   //必得体会
		    				$("#sjjdk").show();
		    				$("#zyjs_bdth").append(e.title);
		    				$("#zxxx_bdth_a").attr("href","../WebSubject/SubMenuPage.htm?id=" + e.id); 
		    				initBdth(topic_id,e.id );
		    				break;
		    			case "yzt" :   //一张图
		    				$("#main3").show();
		    				intitYzt(topic_id,e.id);
		    				
		    				break;
	    			}
          
	    		}
	    		
	    		);*/
	    	}	
	    },  
	     error : function(XMLHttpRequest, textStatus, errorThrown) {  
	          XMLHttpRequest.status;
	          XMLHttpRequest.readyState;
	          textStatus;
	     }  
	});
}



function initPage(data, topic_id)
{
	
	for(var i = 0; i< data.length; i++)
	{
		switch (i)
		{
			case 0: //活动动态.
				initHddt(topic_id, data[i].id);
				$("#zxxx_hddt_a").attr("href","../WebSubject/SubMenuPage.htm?id=" + data[i].id); 
				loadImageNew(topic_id, data[i].flag);
				break;
			case 1:  //工作动态.
				if(data[i].flag=="yzt")
				{
					yztPage(topic_id, data[i].id);
				}
				else
				{
					$("#zyjs_gzdt").append(data[i].title);
					$("#zxxx_gzdt_a").attr("href","../WebSubject/SubMenuPage.htm?id=" + data[i].id); 
					initGzdt(topic_id,data[i].id);
				}
				break;
			case 2:   //相关文件
				if(data[i].flag=="yzt")
				{
					yztPage(topic_id, data[i].id);
				}
				else
				{
					$("#zyjs_xgwj").append(data[i].title);
					$("#zxxx_xgwj_a").attr("href","../WebSubject/SubMenuPage.htm?id=" + data[i].id); 
					initXgwj(topic_id,data[i].id );
				}
				break;
			case 3:   //上级精神
				if(data[i].flag=="yzt")
				{
						yztPage(topic_id, data[i].id);
				}
				else
				{
					$("#zypl").show();
					$("#zyjs_sjjs").append(data[i].title);
					$("#zxxx_sjjs_a").attr("href","../WebSubject/SubMenuPage.htm?id=" + data[i].id); 
					initSjjs(topic_id,data[i].id );
				}
				break;
			case 4:   //必得体会
				if(data[i].flag=="yzt")
				{
					yztPage(topic_id, data[i].id);
				}
				else
				{
					$("#sjjdk").show();
					$("#zyjs_bdth").append(data[i].title);
					$("#zxxx_bdth_a").attr("href","../WebSubject/SubMenuPage.htm?id=" + data[i].id); 
					initBdth(topic_id,data[i].id );
				}
				break;
			case 5 :   //一张图
				yztPage(topic_id, data[i].id);
				
				break;
		}
	}
}


function yztPage(topic_id, id)
{
	$("#main3").show();
	intitYzt(topic_id,id);
}

/**
 * 初始化法动动态.
 */
function initHddt(topic_id,menuId )
{
	var str="";
	$.ajax({  
		type: "POST",  
        url: '../WebSubject/loadSubjectMsgByFlag.json',  
        async: false,
        data:{  
        	topic_id:topic_id,
        	id :menuId,
	    },  
	    cache:false,  
	    dataType:'json',  
	    success:function(data) { 
	    	if(data!=null && data.length>0){
	    		for (var i=0;i<data.length;i++)
	    		{
	    			
	    			var href = "../WebSubject/detailMsgPage.htm?id="+data[i].id+"&menu_id=" +menuId;;
	    			if(data[i].isLink == '1')
	    			{
	    				href=data[i].linkURL;
	    			}
	    			
					str+="<li><a href='"+href+"' target='_blank' title='"+data[i].title+"'>";
					str+=subStr(data[i].title,21);
					str+="</a></li>";
	    		}
	    	}	
	    },  
	     error : function(XMLHttpRequest, textStatus, errorThrown) {  
	          XMLHttpRequest.status;
	          XMLHttpRequest.readyState;
	          textStatus;
	     }  
	});
	
	$("#zxxx_hddt_msgTitle").append(str);
}

function initGzdt(topic_id,menuId )
{
	var str="";
	$.ajax({  
		type: "POST",  
        url: '../WebSubject/loadSubjectMsgByFlag.json',  
        async: false,
        data:{  
        	topic_id:topic_id,
        	id :menuId,
	    },  
	    cache:false,  
	    dataType:'json',  
	    success:function(data) { 
	    	if(data!=null && data.length>0){
	    		for (var i=0;i<data.length;i++)
	    		{
	    			var href = "../WebSubject/detailMsgPage.htm?id="+data[i].id+"&menu_id=" +menuId;;
	    			if(data[i].isLink == '1')
	    			{
	    				href=data[i].linkURL;
	    			}
	    			
	    			
	    			str+="<li><a href='"+href+"' target='_blank' title='"+data[i].title+"'>";
	    			str+=subStr(data[i].title,20);
	    			str+="</a></li>";
	    		}
	    	}	
	    },  
	     error : function(XMLHttpRequest, textStatus, errorThrown) {  
	          XMLHttpRequest.status;
	          XMLHttpRequest.readyState;
	          textStatus;
	     }  
	});
	
	$("#zxxx_gzdt_msgTitle").append(str);
}


function initXgwj(topic_id,menuId )
{
	var str="";
	$.ajax({  
		type: "POST",  
        url: '../WebSubject/loadSubjectMsgByFlag.json',  
        async: false,
        data:{  
        	topic_id:topic_id,
        	id :menuId,
	    },  
	    cache:false,  
	    dataType:'json',  
	    success:function(data) { 
	    	if(data!=null && data.length>0){
	    		for (var i=0;i<data.length;i++)
	    		{
	    			var href = "../WebSubject/detailMsgPage.htm?id="+data[i].id+"&menu_id=" +menuId;;
	    			if(data[i].isLink == '1')
	    			{
	    				href=data[i].linkURL;
	    			}
	    			str+="<li><a href='"+href+"' target='_blank' title='"+data[i].title+"'>";
	    			str+=subStr(data[i].title,20);
	    			str+="</a></li>";

	    		}
	    	}	
	    },  
	     error : function(XMLHttpRequest, textStatus, errorThrown) {  
	          XMLHttpRequest.status;
	          XMLHttpRequest.readyState;
	          textStatus;
	     }  
	});
	
	$("#zxxx_xgwj_msgTitle").append(str);
}


function initSjjs(topic_id,menuId)
{
	
	var str="";
	$.ajax({  
		type: "POST",  
        url: '../WebSubject/loadSubjectMsgByFlag.json',  
        async: false,
        data:{  
        	topic_id:topic_id,
        	id :menuId,
	    },  
	    cache:false,  
	    dataType:'json',  
	    success:function(data) { 
	    	if(data!=null && data.length>0){
	    		for (var i=0;i<data.length;i++)
	    		{
	    			
	    			var href = "../WebSubject/detailMsgPage.htm?id="+data[i].id+"&menu_id=" +menuId;;
	    			if(data[i].isLink == '1')
	    			{
	    				href=data[i].linkURL;
	    			}
	    			
	    			str+="<li><a href='"+href+"' target='_blank' title='"+data[i].title+"'>";
	    			str+=subStr(data[i].title,20);
	    			str+="</a></li>";

	    		}
	    	}	
	    },  
	     error : function(XMLHttpRequest, textStatus, errorThrown) {  
	          XMLHttpRequest.status;
	          XMLHttpRequest.readyState;
	          textStatus;
	     }  
	});
	
	$("#zxxx_sjjs_msgTitle").append(str);
}


function initBdth(topic_id,menuId)
{
	
	var str="";
	$.ajax({  
		type: "POST",  
        url: '../WebSubject/loadSubjectMsgByFlag.json',  
        async: false,
        data:{  
        	topic_id:topic_id,
        	id :menuId,
	    },  
	    cache:false,  
	    dataType:'json',  
	    success:function(data) { 
	    	if(data!=null && data.length>0){
	    		for (var i=0;i<data.length;i++)
	    		{
	    			var href = "../WebSubject/detailMsgPage.htm?id="+data[i].id+"&menu_id=" +menuId;;
	    			if(data[i].isLink == '1')
	    			{
	    				href=data[i].linkURL;
	    			}
	    			
	    			str+="<li><a href='"+href+"' target='_blank' title='"+data[i].title+"'>";
	    			str+=subStr(data[i].title,20);
	    			str+="</a></li>";

	    		}
	    	}	
	    },  
	     error : function(XMLHttpRequest, textStatus, errorThrown) {  
	          XMLHttpRequest.status;
	          XMLHttpRequest.readyState;
	          textStatus;
	     }  
	});
	
	$("#zxxx_bdth_msgTitle").append(str);
}

function intitYzt(topic_id,menuId)
{
	var str="";
	$.ajax({  
		type: "POST",  
        url: '../WebSubject/loadSubjectMsgByFlag.json',  
        async: false,
        data:{  
        	topic_id:topic_id,
        	id :menuId,
	    },  
	    cache:false,  
	    dataType:'json',  
	    success:function(data) { 
	    	if(data!=null && data.length>0){
	    		 $("#main3").append(data[0].content);
	    	}	
	    },  
	     error : function(XMLHttpRequest, textStatus, errorThrown) {  
	          XMLHttpRequest.status;
	          XMLHttpRequest.readyState;
	          textStatus;
	     }  
	});

}
